﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MaximPortal.Model;
using MaximServices.Model;
using MaximServices.Services;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace maxim_portal.Controllers
{
    /// <summary>
    /// 名言
    /// </summary>
    [EnableCors("AllowCors")]
    [Route("api/[controller]")]
    [ApiController]
    public class MottoBaikeController : ControllerBase
    {
        private MottoCheckServices _mottoCheckServices;

        public MottoBaikeController(MottoCheckServices mottoCheckServices)
        {
            _mottoCheckServices = mottoCheckServices;
        }

        /// <summary>
        /// 获取词条，逗号分隔
        /// </summary>
        /// <param name="mottoIds"></param>
        /// <returns></returns>
        // GET: api/MottoCheck
        [HttpGet]
        public ResultModel<MottoBaike> Get([FromQuery]string mottoId)
        {
            if (string.IsNullOrWhiteSpace(mottoId))
            {
                return BuildResult.Error<MottoBaike>("mottoId不能为空", null);
            }

            try
            {
                var data = _mottoCheckServices.MatchBaike(mottoId);

                if (data == null)
                {
                    return BuildResult.Error<MottoBaike>("没有匹配到百科词条", null);
                }

                return BuildResult.Success(data.BaikeInfo);
            }
            catch (Exception e)
            {
                return BuildResult.Error<MottoBaike>(e.Message, null);
            }
        }

        // POST: api/MottoCheck
        /// <summary>
        /// 保存规则
        /// </summary>
        [HttpPost]
        public ResultModel<CreateMottoRuleResultModel> Post([FromBody]AddMottoRuleModel rule)
        {
            return null;
        }


        /// <summary>
        /// 删除规则
        /// </summary>
        /// <param name="id"></param>
        // DELETE: api/MottoCheck/5
        [HttpDelete("{id}")]
        public ResultModel<CreateMottoRuleResultModel> Delete(long id)
        {
            return null;
        }
    }
}
